package com.ecommerce.dal.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.ecommerce.dal.dao.ICompanyCommunicationDAO;
import com.ecommerce.dal.entity.CompanyCommunication;
import com.ecommerce.dal.util.CustomHibernateDAOSupport;

@Repository("companyCommunicationDAO")
public class CompanyCommunicationDAO extends CustomHibernateDAOSupport
		implements ICompanyCommunicationDAO {

	@Override
	public void save(CompanyCommunication companyCommunication) {
		getHibernateTemplate().save(companyCommunication);

	}

	@Override
	public void update(CompanyCommunication companyCommunication) {
		getHibernateTemplate().update(companyCommunication);

	}

	@Override
	public void delete(CompanyCommunication companyCommunication) {
		getHibernateTemplate().delete(companyCommunication);

	}

	@Override
	public List<CompanyCommunication> findByCompanyId(long companyId) {
		List list = getHibernateTemplate()
				.find("select companyCommunication from CompanyCommunication companyCommunication inner join companyCommunication.company company where company.companyId = ?",
						companyId);
		return ((list != null && list.size()>0) ?  list : null) ;
	}

	@Override
	public List<CompanyCommunication> findByCompanyIdAndCommunicationId(
			long companyId, int communicationId) {
		List list = getHibernateTemplate()
				.find("select companyCommunication from CompanyCommunication companyCommunication inner join companyCommunication.company company inner join companyCommunication.communication communication where company.companyId = ? and communication.communicationId = ?",
						companyId, communicationId);
		return ((list != null && list.size()>0) ?  list : null) ;
	}

}
